home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / libqtools / bsp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-18  |  11.5 KB  |  435 lines

  1. #ifndef    BSP_H
  2. #define    BSP_H
  3. /*
  4.  * ============================================================================
  5.  * structures
  6.  * ============================================================================
  7.  */
  8.  
  9. /* upper design bounds */
  10. #define    MAX_MAP_HULLS        4
  11. #define    MAX_HULL_POINTS        32
  12. #define    MAX_HULL_EDGES        64
  13.  
  14. #define    MAGIC_BSP_Q2        MKID('I','B','S','P')    /* 0x49425350 */
  15.  
  16. #define BSP_VERSION_Q1        29
  17. #define BSP_VERSION_Q2        38
  18.  
  19. struct dmodel_t {
  20.   float mins[3], maxs[3];
  21.   float origin[3];
  22.   int headnode[MAX_MAP_HULLS];
  23.   /* not including the solid leaf 0 */
  24.   int visleafs;
  25.   int firstface, numfaces;
  26. };
  27.  
  28. struct dmodel2_t {
  29.   float mins[3], maxs[3];
  30.   /* for sounds or lights */
  31.   float origin[3];
  32.   int headnode;
  33.   /*
  34.    * submodels just draw faces
  35.    * without walking the bsp tree
  36.    */
  37.   int firstface, numfaces;
  38. };
  39.  
  40. struct dmiptexlump_t {
  41.   int nummiptex;
  42.   /* [nummiptex] */
  43.   int dataofs[4];
  44. };
  45.  
  46. struct dvertex_t {
  47.   float point[3];
  48. };
  49.  
  50. /* 0-2 are axial planes */
  51. #define    PLANE_X            0
  52. #define    PLANE_Y            1
  53. #define    PLANE_Z            2
  54.  
  55. /* 3-5 are non-axial planes snapped to the nearest */
  56. #define    PLANE_ANYX        3
  57. #define    PLANE_ANYY        4
  58. #define    PLANE_ANYZ        5
  59.  
  60. /* planes (x&~1) and (x&~1)+1 are allways opposites */
  61.  
  62. struct dplane_t {
  63.   float normal[3];
  64.   float dist;
  65.   /* PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate */
  66.   int type;
  67. };
  68.  
  69. /*
  70.  * contents flags are seperate bits
  71.  * a given brush can contribute multiple content bits
  72.  * multiple brushes can be in a single leaf
  73.  *
  74.  * these definitions also need to be in q_shared.h!
  75.  *
  76.  * lower bits are stronger, and will eat weaker brushes completely
  77.  */
  78. #define    CONTENTS_EMPTY        -1
  79. #define    CONTENTS_SOLID        -2
  80. #define    CONTENTS_WATER        -3
  81. #define    CONTENTS_SLIME        -4
  82. #define    CONTENTS_LAVA        -5
  83. #define    CONTENTS_SKY        -6
  84.  
  85. #define    CONTENTS2_SOLID        (1<<0)                /* an eye is never valid in a solid */
  86. #define    CONTENTS2_WINDOW    (1<<1)                /* translucent, but not watery */
  87. #define    CONTENTS2_AUX        (1<<2)
  88. #define    CONTENTS2_LAVA        (1<<3)
  89. #define    CONTENTS2_SLIME        (1<<4)
  90. #define    CONTENTS2_WATER        (1<<5)
  91. #define    CONTENTS2_MIST        (1<<6)
  92.  
  93. /* remaining contents are non-visible, and don't eat brushes */
  94. #define    CONTENTS_AREAPORTAL    (1<<15)
  95. #define    CONTENTS_PLAYERCLIP    (1<<16)
  96. #define    CONTENTS_MONSTERCLIP    (1<<17)
  97. /* currents can be added to any other contents, and may be mixed */
  98. #define    CONTENTS_CURRENT_0    (1<<18)
  99. #define    CONTENTS_CURRENT_90    (1<<19)
  100. #define    CONTENTS_CURRENT_180    (1<<20)
  101. #define    CONTENTS_CURRENT_270    (1<<21)
  102. #define    CONTENTS_CURRENT_UP    (1<<22)
  103. #define    CONTENTS_CURRENT_DOWN    (1<<23)
  104. #define    CONTENTS_ORIGIN        (1<<24)                /* removed before bsping an entity */
  105. #define    CONTENTS_MONSTER    (1<<25)                /* should never be on a brush, only in game */
  106. #define    CONTENTS_DEADMONSTER    (1<<26)
  107. #define    CONTENTS_DETAIL        (1<<27)                /* brushes to be added after vis leafs */
  108. #define    CONTENTS_TRANSLUCENT    (1<<28)                /* auto set if any surface has trans */
  109. #define    CONTENTS_LADDER        (1<<29)
  110.  
  111. #define    SURF_LIGHT        (1<<0)                /* value will hold the light strength */
  112. #define    SURF_SLICK        (1<<1)                /* effects game physics */
  113. #define    SURF_SKY        (1<<2)                /* don't draw, but add to skybox */
  114. #define    SURF_WARP        (1<<3)                /* turbulent water warp */
  115. #define    SURF_TRANS33        (1<<4)
  116. #define    SURF_TRANS66        (1<<5)
  117. #define    SURF_FLOWING        (1<<6)                /* scroll towards angle */
  118. #define    SURF_NODRAW        (1<<7)                /* don't bother referencing the texture */
  119. #define    SURF_HINT        (1<<8)                /* make a primary bsp splitter */
  120. #define    SURF_SKIP        (1<<9)                /* completely ignore, allowing non-closed brushes */
  121.  
  122. struct dnode_t {
  123.   int planenum;
  124.   /* negative numbers are -(leafs+1), not nodes */
  125.   short int children[2];
  126.   /* for sphere culling */
  127.   short int mins[3];
  128.   short int maxs[3];
  129.   unsigned short int firstface;
  130.   /* counting both sides */
  131.   unsigned short int numfaces;
  132. };
  133.  
  134. struct dnode2_t {
  135.   int planenum;
  136.   /* negative numbers are -(leafs+1), not nodes */
  137.   int children[2];
  138.   /* for sphere culling */
  139.   short int mins[3];
  140.   short int maxs[3];
  141.   unsigned short int firstface;
  142.   /* counting both sides */
  143.   unsigned short int numfaces;
  144. };
  145.  
  146. struct dclipnode_t {
  147.   int planenum;
  148.   /* negative numbers are contents */
  149.   short int children[2];
  150. };
  151.  
  152. struct texinfo {
  153.   /* [s/t][xyz offset] */
  154.   float vecs[2][4];
  155.   int miptex;
  156.   int flags;
  157. };
  158.  
  159. struct texinfo2 {
  160.   /* [s/t][xyz offset] */
  161.   float vecs[2][4];
  162.   /* miptex flags + overrides */
  163.   int flags;
  164.   /* light emission, etc */
  165.   int value;
  166.   /* texture name (textures/.wal) */
  167.   char texture[32];
  168.   /* for animations, -1 = end of chain */
  169.   int nexttexinfo;
  170. };
  171.  
  172. /* sky or slime, no lightmap or 256 subdivision */
  173. #define    TEX_SPECIAL        (1<<0)                /* aequivalent to 1 */
  174. /* extensions to bsp-type added by niels */
  175. #define    TEX_WATER        (1<<1)
  176. #define    TEX_SLIME        (1<<2)
  177. #define    TEX_LAVA        (1<<3)
  178. #define    TEX_SKY            (1<<4)
  179.  
  180. /*
  181.  * note that edge 0 is never used, because negative edge nums are used for
  182.  * counterclockwise use of the edge in a face
  183.  */
  184. struct dedge_t {
  185.   /* vertex numbers */
  186.   unsigned short int v[2];
  187. };
  188.  
  189. #define    MAXLIGHTMAPS        4
  190. struct dface_t {
  191.   short int planenum;
  192.   short int side;
  193.   /* we must support > 64k edges */
  194.   int firstedge;
  195.   short int numedges;
  196.   short int texinfo;
  197.   /* lighting info */
  198.   unsigned char styles[MAXLIGHTMAPS];
  199.   /* start of [numstyles*surfsize] samples */
  200.   int lightofs;
  201. };
  202.  
  203. #define    AMBIENT_WATER        0
  204. #define    AMBIENT_SKY        1
  205. #define    AMBIENT_SLIME        2
  206. #define    AMBIENT_LAVA        3
  207.  
  208. /* automatic ambient sounds */
  209. #define    NUM_AMBIENTS        4
  210.  
  211. /*
  212.  * leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas
  213.  * all other leafs need visibility info
  214.  */
  215. struct dleaf_t {
  216.   int contents;
  217.   /* -1 = no visibility info */
  218.   int visofs;
  219.   /* for frustum culling */
  220.   short int mins[3];
  221.   short int maxs[3];
  222.   unsigned short int firstmarksurface;
  223.   unsigned short int nummarksurfaces;
  224.   unsigned char ambient_level[NUM_AMBIENTS];
  225. };
  226.  
  227. struct dleaf2_t {
  228.   /* OR of all brushes (not needed?) */
  229.   int contents;
  230.  
  231.   short int cluster;
  232.   short int area;
  233.   /* for frustum culling */
  234.   short int mins[3];
  235.   short int maxs[3];
  236.   unsigned short int firstleafface;
  237.   unsigned short int numleaffaces;
  238.   unsigned short int firstleafbrush;
  239.   unsigned short int numleafbrushes;
  240. };
  241.  
  242. struct dbrushside2_t {
  243.   /* facing out of the leaf */
  244.   unsigned short int planenum;
  245.   short int texinfo;
  246. };
  247.  
  248. struct dbrush2_t {
  249.   int firstside;
  250.   int numsides;
  251.   int contents;
  252. };
  253.  
  254. #define    ANGLE_UP        -1
  255. #define    ANGLE_DOWN        -2
  256.  
  257. /*
  258.  * the visibility lump consists of a header with a count, then
  259.  * byte offsets for the PVS and PHS of each cluster, then the raw
  260.  * compressed bit vectors
  261.  */
  262. #define    DVIS_PVS        0
  263. #define    DVIS_PHS        1
  264. struct dvis2_t {
  265.   int numclusters;
  266.   /* bitofs[numclusters][2] */
  267.   int bitofs[8][2];
  268. };
  269.  
  270. /*
  271.  * each area has a list of portals that lead into other areas
  272.  * when portals are closed, other areas may not be visible or
  273.  * hearable even if the vis info says that it should be
  274.  */
  275. struct dareaportal2_t {
  276.   int portalnum;
  277.   int otherarea;
  278. };
  279.  
  280. struct darea2_t {
  281.   int numareaportals;
  282.   int firstareaportal;
  283. };
  284.  
  285. struct dpair {
  286.   int offset, size;
  287. };
  288.  
  289. struct bspheader {
  290.   int version;
  291.   struct dpair entities, planes, miptex, vertices, visilist
  292.    ,nodes, texinfo, faces, lightmaps, clipnodes
  293.    ,leaves, lface, edges, ledges, models;
  294. };
  295.  
  296. struct bspheader2 {
  297.   int identifier, version;
  298.   struct dpair entities, planes, vertices, visilist
  299.    ,nodes, texinfo, faces, lightmaps
  300.    ,leaves, lface, leafbrushes, edges, ledges, models
  301.    ,brushes, brushsides, pops, areas, areaportals;
  302. };
  303.  
  304. struct visdata {
  305.   char procName[32];
  306.   int size;
  307. };
  308.  
  309. /*
  310.  * ============================================================================
  311.  * bsp-tree related
  312.  * ============================================================================
  313.  */
  314.  
  315. /* the exact bounding box of the brushes is expanded some for the headnode */
  316. /* volume.  is this still needed? */
  317. #define    SIDESPACE            24
  318.  
  319. #define ON_EPSILON            0.05
  320. #define    POINT_EPSILON            0.01
  321. #define    DISTEPSILON            0.01
  322. #define    T_EPSILON            0.01
  323. #define    ZERO_EPSILON            0.001
  324. #define CONTINUOUS_EPSILON        0.001
  325. #define    ANGLE_EPSILON            0.00001
  326.  
  327. #define BOGUS_RANGE            18000
  328.  
  329. #ifdef DYNAMIC_EDGES
  330. struct visfacet {
  331.   struct visfacet *next;
  332.   int planenum;
  333.   int planeside;                        /* which side is the front of the face */
  334.   int texturenum;
  335.   int contents[2];                        /* 0 = front side */
  336.   struct visfacet *original;                    /* face on node */
  337.   int outputnumber;                        /* only valid for original faces after */
  338.   /* write surfaces */
  339.   short int numpoints;
  340.   vec3_t *pts;                            /* FIXME: change to use winding_t */
  341.   int *edges;
  342. } __packed;                            /* 36 + 384 + 128 = 548 */
  343.  
  344. #else
  345. struct visfacet {
  346.   struct visfacet *next;
  347.   int planenum;
  348.   int planeside;                        /* which side is the front of the face */
  349.   int texturenum;
  350.   int contents[2];                        /* 0 = front side */
  351.   struct visfacet *original;                    /* face on node */
  352.   int outputnumber;                        /* only valid for original faces after */
  353.   /* write surfaces */
  354.   /*int numpoints; */
  355.   short int numpoints;                        /* maximum is MAXEDGES */
  356.   vec3_t pts[MAXEDGES];                        /* FIXME: change to use winding_t */
  357.   int edges[MAXEDGES];
  358. } __packed;                            /* 36 + 384 + 128 = 548 */
  359.  
  360.                     /* 34 + 120 +  36 = 190 */
  361. #endif
  362.  
  363. struct surface {
  364.   struct surface *next;
  365.   struct surface *original;                    /* before BSP cuts it up */
  366.   int planenum;
  367.   int outputplanenum;                        /* only valid after WriteSurfacePlanes */
  368.   vec3_t mins, maxs;
  369.   bool onnode;                            /* true if surface has already been used */
  370.   /* as a splitting node */
  371.   struct visfacet *faces;                    /* links to all the faces on either side of the surf */
  372. } __packed;                            /* 48 */
  373.  
  374. /*
  375.  * there is a node_t structure for every node and leaf in the bsp tree
  376.  */
  377. #define    PLANENUM_LEAF            -1
  378.  
  379. struct node {
  380.   vec3_t mins, maxs;                        /* bounding volume, not just points inside */
  381.   /* information for decision nodes */
  382.   int planenum;                            /* -1 = leaf node */
  383.   int outputplanenum;                        /* only valid after WriteNodePlanes */
  384.   int firstface;                        /* decision node only */
  385.   int numfaces;                            /* decision node only */
  386.   struct node *children[2];                    /* only valid for decision nodes */
  387.   struct visfacet *faces;                    /* decision nodes only, list for both sides */
  388.   /* information for leafs */
  389.   int contents;                            /* leaf nodes (0 for decision nodes) */
  390.   struct visfacet **markfaces;                    /* leaf nodes only, point to node faces */
  391.   struct portal *portals;
  392.   int visleafnum;                        /* -1 = solid */
  393.   int valid;                            /* for flood filling */
  394.   /*int occupied;                                                              / light number in leaf for outside filling / */
  395.   short int occupied;                        /* maximum in number of entities */
  396. } __packed;                            /* 76 */
  397.  
  398.                     /* 74 */
  399.  
  400. /*
  401.  * ============================================================================
  402.  * globals
  403.  * ============================================================================
  404.  */
  405.  
  406. extern bool newBsp, newLit, newVis;
  407.  
  408. /* light */
  409. extern bool waterlit, extra, doradiosity;
  410. extern float scale, range;
  411.  
  412. /* qbsp */
  413. extern bool watervis, slimevis;
  414. extern bool nofill, notjunc, noclip, onlyents, usehulls;
  415. extern int subdivide, hullnum;
  416.  
  417. /* vis */
  418. extern bool fastvis;
  419. extern int vislevel;
  420.  
  421. /*
  422.  * ============================================================================
  423.  * prototypes
  424.  * ============================================================================
  425.  */
  426.  
  427. #include "memory.h"
  428.  
  429. bool AddBSP(struct palpic *inPic, struct rawdata *inData, char *bspName, operation procOper, filetype inType);
  430. bool ExtractBSP(HANDLE file, FILE * script, char *destDir, char *entryName, filetype outType, operation procOper, bool recurse);
  431. struct memory *LoadBSP(HANDLE bspFile, int availLoad, unsigned char versionLoad);
  432. void WriteBSP(HANDLE bspFile, __memBase, unsigned char versionSave);
  433.  
  434. #endif
  435.